package longcaisuyun.longcai.com.utils;

import android.util.Log;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Administrator on 2016/4/15.
 */
public class TimerUtils {
    /**
     * string类型转化为Date类型
     *
     * @param strTime
     * @param formatType 要转化的日期格式类型
     * @return
     * @throws ParseException
     */
    public static Date stringToDate(String strTime, String formatType)
            throws ParseException {
        SimpleDateFormat formatter = new SimpleDateFormat(formatType);
        Date date = null;
        date = formatter.parse(strTime);
        return date;
    }

    // date要转换的date类型的时间
    public static long dateToLong(Date date) {
        return date.getTime();
    }

    /**
     * 获取当前系统日期
     *
     * @return
     */
    public static String getCurrentDate() {
        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateStr = format.format(date);
        return dateStr;
    }

    /**
     * 获取当前系统时间---秒数
     *
     * @return
     */
    public static long getCurrentTimes() {
        Date date = new Date();
        return date.getTime();
    }

    /**
     * 将毫秒转化为 *天*时*分*秒
     *
     * @param mss
     * @return
     */
    public static String formatDuring(long mss) {
        long days = mss / (1000 * 60 * 60 * 24);
        long hours = (mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60);
        long minutes = (mss % (1000 * 60 * 60)) / (1000 * 60);
        long seconds = (mss % (1000 * 60)) / 1000;
        if (days > 0) {
            return days + "天 " + hours + "小时 " + minutes + "分" + seconds
                    + " 秒 ";
        } else if (hours > 0) {
            return hours + "小时 " + minutes + "分" + seconds + "秒 ";
        } else if (minutes > 0) {
            return minutes + "分" + seconds + "秒 ";
        } else if (seconds > 0) {
            return seconds + "秒 ";
        } else {
            return "0";
        }
    }
    public static String Second(long mss) {

        long seconds = mss / 1000;
        if(seconds>0){
            return seconds+"秒";
        }else{
            return 0+"秒";
        }

    }


    public static String formatRemainingTime(Date begin, Date end) {

        return Second(end.getTime() - begin.getTime());
    }



    // 把字符串转为日期
    public static  DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    public static Date ConverToDate(String strDate) throws Exception {

        return df.parse(strDate);
    }
}
